import axios from "axios";
// http请求拦截器
axios.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);
// http响应拦截器
axios.interceptors.response.use(
  data => {
    return data.data;
  },
  error => {
    if (error.response) {
      console.log(error.response)
    }
    return Promise.reject(error);
  }
);

axios.defaults.withCredentials = false;

export default class Base {
  //获取
  get(url, loading = false, config = {}) {
    return axios.get(url, config).catch(err => {
      console.error(err.message || err);
    });
  }
  //新增
  post(url, data, loading = false, config = {}) {
    return axios.post(url, data, config);
  }
  //修改
  put(url, data, loading = false, config = {}) {
    return axios.put(url, data, config);
  }
  //删除
  delete(url, loading = false, config = {}) {
    return axios.delete(url, config);
  }
}
